package com.dding.cms.base.web.widget;

import static com.dding.cms.base.web.ActionConstants.WIDGET_SEPERATOR;

import java.util.Set;

import org.dding.core.util.StringUtils;

import com.dding.cms.base.entity.Content;

public class WidgetUtils {

	public static String[] parserName(String name) {
		if (StringUtils.isNotEmpty(name)) {
			int index = name.indexOf(WIDGET_SEPERATOR);
			if (index > 0) {
				return name.split(WIDGET_SEPERATOR);
			}
		}
		return new String[] { name };
	}

	public static String formatWigetName(String name) {
		String[] value = name.split(WIDGET_SEPERATOR);
		if (value != null && value.length == 1) {
			return name;
		} else if (value != null && value.length == 2) {
			return value[0];
		}
		return name;
	}

	@SuppressWarnings("unchecked")
	public static Set<String> getContentColumns() {
		return Content.getMetaModel().getColumnMetadata().keySet();
	}
}
